package io.github.harmonly.skyblock.command;

import dev.jorel.commandapi.CommandAPI;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
import dev.jorel.commandapi.arguments.StringArgument;
import io.github.harmonly.skyblock.manager.DataManager;

public class WarpCommand implements SBCommand {

    @Override
    public String name() {
        return "warp";
    }

    @Override
    public void register() {
        new CommandAPICommand("hub")
                .executesPlayer((sender, args) -> {
                    DataManager.getProfileData(sender).ifPresent(profileData -> profileData.warp("hub"));
                })
                .register();
        new CommandAPICommand("island")
                .withAliases("is")
                .executesPlayer((sender, args) -> {
                    DataManager.getProfileData(sender).ifPresent(profileData -> profileData.warp("island"));
                })
                .register();
        new CommandAPICommand("warp")
                .withArguments(new StringArgument("name").replaceSuggestions(ArgumentSuggestions.strings(
                        "hub", "island"
                )))
                .executesPlayer((sender, args) -> {
                    args.getOptional(0).ifPresent(a0 -> {
                        String name = (String) a0;
                        DataManager.getProfileData(sender).ifPresent(profileData -> profileData.warp(name));
                    });
                })
                .register();
    }

    @Override
    public void unregister() {
        CommandAPI.unregister("hub");
        CommandAPI.unregister("island");
        CommandAPI.unregister("warp");
    }
}
